import { createWebHashHistory, createRouter } from 'vue-router'

const routes = [
    {
        path: '/login',
        name: 'login',
        meta: {
            keepAlive: false,
            isLogin:false
        },
        component: () => import('@/pages/login/login.vue'),
    },  
    {
        path: '/index',
        name: 'index',
        component: () => import('@/pages/index/index.vue'),
    },
    {
        path: '/',
        component: () => import('@/pages/layout/layout.vue'),
        redirect: { name: 'index' },
        children: [{
            path: 'data',
            name: 'data',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/data/data.vue')
        },{
            path: 'riskControl',
            name: 'riskControl',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/riskControl/riskControl.vue')
        },{
            path: 'remoteIdSpectRecord',
            name: 'remoteIdSpectRecord',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/remoteIdSpectRecord/remoteIdSpectRecord.vue')
        },{
            path: 'fiveGASpectRecord',
            name: 'fiveGASpectRecord',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/fiveGASpectRecord/fiveGASpectRecord.vue')
        },{
            path: 'device',
            name: 'device',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/device/device.vue')
        },{
            path: 'deviceGroup',
            name: 'deviceGroup',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/deviceGroup/deviceGroup.vue')
        },{
            path: 'fiveGAdevice',
            name: 'fiveGAdevice',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/fiveGAdevice/fiveGAdevice.vue')
        },{
            path: 'deviceLog',
            name: 'deviceLog',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/deviceLog/deviceLog.vue')
        },{
            path: 'spectLog',
            name: 'spectLog',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/spectLog/spectLog.vue')
        },{
            path: 'operateLog',
            name: 'operateLog',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/operateLog/operateLog.vue')
        }, {
            path: 'messageLog',
            name: 'messageLog',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/messageLog/messageLog.vue')
        }, {
            path: 'whiteList',
            name: 'whiteList',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/whiteList/whiteList.vue')
        }, {
            path: 'report',
            name: 'report',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/report/report.vue')
        },{
            path: 'setting',
            name: 'setting',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/setting/setting.vue')
        },{
            path: 'droneModel',
            name: 'droneModel',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/droneModel/droneModel.vue')
        },{
            path: 'spectIdentity',
            name: 'spectIdentity',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/spectIdentity/spectIdentity.vue')
        },{
            path: 'auth',
            name: 'auth',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/auth/auth.vue')
        },{
            path: 'user',
            name: 'user',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/user/user.vue')
        },{
            path: 'role',
            name: 'role',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/role/role.vue')
        },{
            path: 'invitationCode',
            name: 'invitationCode',
            meta: {
                isLogin: true
            },
            component: () => import('@/pages/view/invitationCode/invitationCode.vue')
        }]
    }
]

const router = createRouter({
    history: createWebHashHistory(),
    routes,
})
router.beforeEach((to, _, next) => {
    // 拦截无权限页面
    if (to.meta.isLogin && !useLocal().token) return next({ name: 'login' })
    next()
});
export default router